package com.xmkj.bearbiz;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.StrictMode;
import android.support.multidex.MultiDex;
import android.util.DisplayMetrics;

import com.common.utils.ContextUtils;
import com.common.widget.loadingView.LoadingLayout;
import com.common.widget.toast.ToastManager;
import com.xmkj.bearbiz.lisener.GlidePauseOnScrollListener;
import com.xmkj.bearbiz.utils.GlideImageLoader;

import java.util.Locale;

import cn.finalteam.galleryfinal.CoreConfig;
import cn.finalteam.galleryfinal.FunctionConfig;
import cn.finalteam.galleryfinal.GalleryFinal;
import cn.finalteam.galleryfinal.ThemeConfig;
import cn.jpush.android.api.JPushInterface;


/*******************************
 * MainApplication
 * @author syc
 * created at 2017/4/13 上午 10:38
 ********************************/
public class MainApplication extends ContextUtils {
    private static Context context;
    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        initApp();
    }
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }



/*    *//**
     * 网络操作相关的子线程
     *//*
    Runnable networkTask = new Runnable() {

        @Override
        public void run() {
            initEasyUi();
        }
    };*/
    private void initApp() {
        JPushInterface.init(this);            // 初始化 JPush
        JPushInterface.setDebugMode(true);
//        String registrationID = JPushInterface.getRegistrationID(this);
        ToastManager.init(getApplicationContext());
        initLoadingView();
        initGalleryFinal();
    }



    private void initGalleryFinal() {
        //设置主题
        ThemeConfig theme = ThemeConfig.CYAN;
        //   ThemeConfig theme = new ThemeConfig.Builder()
        //    .build();
        //配置功能
        FunctionConfig functionConfig = new FunctionConfig.Builder()
                .setEnableCamera(true)
                .setEnableEdit(true)
                .setEnableCrop(true)
                .setEnableRotate(true)
                .setCropSquare(true)
                .setEnablePreview(true)
                .build();
        CoreConfig coreConfig = new CoreConfig.Builder(this, new GlideImageLoader(), theme)
                .setFunctionConfig(functionConfig)
                .setPauseOnScrollListener(new GlidePauseOnScrollListener(false, true))
                .build();
        GalleryFinal.init(coreConfig);
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        builder.detectFileUriExposure();
    }


    // 初始化页面预加载View
    private void initLoadingView() {
        LoadingLayout.getConfig()
                .setEmptyText("暂无数据")
                .setNoNetworkText("无网络连接，请检查您的网络···")
                .setErrorImage(R.mipmap.loadingview_error)
                .setEmptyImage(R.mipmap.loadingview_empty)
                .setNoNetworkImage(R.mipmap.loadingview_error)
                .setAllTipTextColor(R.color.grey)
                .setAllTipTextSize(14)
                .setReloadButtonText("点我重试")
                .setReloadButtonTextSize(14)
                .setReloadButtonTextColor(R.color.grey)
                .setReloadButtonWidthAndHeight(150, 40)
                .setAllPageBackgroundColor(R.color.view_background_color);
//        .setLoadingPageLayout(R.layout.define_loading_page)
    }

    private void getLanguage(boolean is_turkey) {

        Resources resources = getResources();

        Configuration config = resources.getConfiguration();

        DisplayMetrics dm = resources.getDisplayMetrics();

        if (is_turkey) {
            Locale locale2 = new Locale("tr", "TR");
            config.locale = locale2; // 土耳其

        } else {
            config.locale = Locale.getDefault();
        }

        resources.updateConfiguration(config, dm);

    }


}
